/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package basic;

import gui.CoreWin;
import logic.Varpool;
import gui.MainWin;
import sql.*;

/**
 *
 * @author Freshman
 */
public class CORE {

    private CoreWin cw = null;
    private static int loadstate = 0;
    private Varpool vap= null;
    private Dbconnection dbcon = null;
    private GetTables gtb = null;
    private MainWin mw = null;

    public CORE(CoreWin aThis) {
        cw = aThis;
        loadProgram();
    }

    private void loadProgram() {
        for (int i = loadstate; i < 10; i++) {
            if (i == 0) {
                this.vap = new Varpool();
                waiting();
                cw.updateLoader(10, "Variablen fixiert");
            } else if (i == 1) {
                this.dbcon = new Dbconnection(vap);
                waiting();
                cw.updateLoader(30, "Datenbank gefunden und verankert");
            } else if (i == 2) {
                this.gtb = new GetTables(vap);
                waiting();
                cw.updateLoader(60, "Tabellen organisiert");
            }else if (i == 3) {
                this.mw = new MainWin(this);
                waiting();
                cw.updateLoader(95, "Maler für GUI engagiert");
            }
        }
        waiting();
        cw.dispose();
        mw.setVisible(true);
    }

    public static void waiting() {

        long t0, t1;

        t0 = System.currentTimeMillis();

        do {
            t1 = System.currentTimeMillis();
        } while ((t1 - t0) < 1000);
        loadstate += 1;
    }
    
    public Varpool getVariable() {
        return vap;
    }
}
